﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using You.Niao.ShaFa.IDAL;
using You.Niao.ShaFa.Model;
using You.Niao.User.Model;
using Common;
using AOP;

namespace You.Niao.ShaFa.Area.Controllers
{
    public class ShaFaAPIController : Controller
    {
        
        // GET: /ShaFaAPI/
        public IShaFaInfo ishafainfo;
        public IArea iarea;
        public ICity icity;
        public IProvince iprovince;
        public IPublish ipublish;
        public IRelease irelease;

        public ShaFaAPIController(IShaFaInfo _ishafainfo, IArea _iarea, ICity _icity, IProvince _iprovince, IPublish _ipublish, IRelease _irelease)
        {
            ishafainfo = _ishafainfo;
            iarea = _iarea;
            icity = _icity;
            iprovince = _iprovince;
            ipublish = _ipublish;
            irelease = _irelease;
        }
        
        [HttpPost]
        public JsonResult Create(ShaFaInfo data)
        {
            JsonResponse JR = new JsonResponse();
            JR.isSuccess = false;
            return Json(JR);
        }

        [HttpGet]
        public JsonResult GetArea(Model.area model)
        {
            List<Model.area> AreaList = iarea.GetList(model.FID);
            return Json(AreaList,JsonRequestBehavior.AllowGet);
        }
        [HttpGet]
        public JsonResult GetCity(Model.city model)
        {
            List<Model.city> CityList = icity.GetList(model.FID);
            return Json(CityList, JsonRequestBehavior.AllowGet);
        }
        [HttpGet]
        public JsonResult GetProvince()
        {
            PcaModel ProvinceList=iprovince.GetList();
            return Json(ProvinceList, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public JsonResult Publish(Publish Pmodel)
        {
            Users users=new Users();
            int UserID;
            int.TryParse(CommonCookie.GetCookie("UserID"), out UserID);
            Pmodel.UserID = UserID;
            Pmodel.NickName=users.NickName;
            Pmodel.Avatar = users.Avatar;
            Pmodel.NickName = CommonCookie.GetCookie("NickName");
            Pmodel.Avatar = CommonCookie.GetCookie("Avatar");
            int number = ipublish.Publish(Pmodel);
            return Json(number);
        }

       
        [HttpPost]
        public JsonResult Release(Release Rmodel)
        {
            Users u=new Users();
            int UserID;
            int.TryParse(CommonCookie.GetCookie("UserID"), out UserID);
            Rmodel.UserID = u.UserID;
            Rmodel.NickName = u.NickName;
            Rmodel.NickName = CommonCookie.GetCookie("NickName");
            int number = irelease.Release(Rmodel);
            return Json(number);
        }
    }
}
